home *** CD-ROM | disk | FTP | other *** search
/ Game.EXE 2001 January / Game.EXE_01_2001.iso / demos / Blade of Darkness / data1.cab / Program_Executable_Files / Lib / Torchs.py < prev    next >
Encoding:
Text File  |  2000-11-16  |  6.2 KB  |  196 lines

  1. import Bladex
  2. import InitDataField
  3. import AuxFuncs
  4. import Actions
  5. import Reference
  6.  
  7.  
  8. OFF=0
  9. ON=1
  10. DEAD=0
  11. ALIVE=1
  12.  
  13.  
  14. tipos_antorcha=("Antorcha", "Antorchaenpared", "Palangana")
  15.  
  16.  
  17. class TorchObj:
  18.  
  19.     pass
  20.  
  21.  
  22. def ExtingueGradual(torchobj, torchspot, torchfire, intensity_var, fire_var, fire_int, OnEndExtinctionFunc, OnEndExtinctionArgs):
  23.     if torchspot.Intensity>0.0:
  24.         torchspot.Intensity=torchspot.Intensity-intensity_var
  25.     else:
  26.         torchspot.Intensity = 0
  27.     fire_int=fire_int+fire_var
  28.     torchfire.Intensity=fire_int
  29.     if torchfire.Intensity>=30.0:
  30. #        print "Apagada..."
  31.         torchobj.LiveStatus=DEAD
  32.         torchobj.LightStatus=OFF
  33.         if OnEndExtinctionFunc:
  34.             apply(OnEndExtinctionFunc, OnEndExtinctionArgs)
  35.         return
  36.     Bladex.AddScheduledFunc(Bladex.GetTime()+0.1, ExtingueGradual, (torchobj, torchspot, torchfire, intensity_var, fire_var, fire_int, OnEndExtinctionFunc, OnEndExtinctionArgs))
  37.  
  38.  
  39. def ExtingueAntorcha(torch_name, OnEndExtinctionFunc="", OnEndExtinctionArgs=()):
  40.     torch=Bladex.GetEntity(torch_name)
  41.     torchspot=AuxFuncs.GetSpot(torch)
  42.     torchfire=AuxFuncs.GetFire(torch)
  43.     torchobj=torch.Data.torchobjdata
  44.     if torchspot.Intensity<=0.0:
  45. #        print "Ya esta apagada..."
  46.         return
  47.     intensity_var=torchspot.Intensity/20.0
  48.     fire_var=(30.0-torchfire.Intensity)/60.0
  49.     fire_int=torchfire.Intensity
  50.     Bladex.AddScheduledFunc(Bladex.GetTime()+0.1, ExtingueGradual, (torchobj, torchspot, torchfire, intensity_var, fire_var, fire_int, OnEndExtinctionFunc, OnEndExtinctionArgs))
  51.     if Reference.EntitiesObjectData.has_key(torch_name): del Reference.EntitiesObjectData[torch_name]
  52.  
  53. def EnciendeGradual(torchobj, torchspot, torchfire, intensity_var, fire_var, fire_int):
  54.     torchspot.Intensity=torchspot.Intensity+intensity_var
  55.     fire_int=fire_int-fire_var
  56.     torchfire.Intensity=fire_int
  57.     if torchspot.Intensity>=torchobj.LightIntensity:
  58. #        print "Encendida..."
  59.         torchobj.LightStatus=ON
  60.         return
  61.     Bladex.AddScheduledFunc(Bladex.GetTime()+0.1, EnciendeGradual, (torchobj, torchspot, torchfire, intensity_var, fire_var, fire_int))
  62.  
  63.  
  64. def EnciendeAntorcha(torch_name):
  65.     torch=Bladex.GetEntity(torch_name)
  66.     torchspot=AuxFuncs.GetSpot(torch)
  67.     torchfire=AuxFuncs.GetFire(torch)
  68.     torchobj=torch.Data.torchobjdata
  69.     if torchobj.LightStatus==ON:
  70. #        print "Ya esta encendida..."
  71.         return
  72.     intensity_var=torchobj.LightIntensity/20.0
  73.     fire_var=(10.0-torchobj.FireIntensity)/20.0
  74.     torchfire.Intensity=10.0
  75.     fire_int=torchfire.Intensity
  76.     Bladex.AddScheduledFunc(Bladex.GetTime()+0.1, EnciendeGradual, (torchobj, torchspot, torchfire, intensity_var, fire_var, fire_int))
  77.     Reference.EntitiesObjectData[torch_name]= Reference.DefaultObjectData["AntorchaFuego"]
  78.  
  79. def EnciendeEstaAntorcha(person_name, event_name):
  80.     pj=Bladex.GetEntity(person_name)
  81.     pj.DelAnmEventFunc(event_name)
  82.     torch=pj.Data.obj_used
  83.     torchobj=torch.Data.torchobjdata
  84.     objright=Bladex.GetEntity(pj.InvRight)
  85.     objrighttorch=objright.Data.torchobjdata
  86.     if objrighttorch.LightStatus==OFF and torchobj.LightStatus==ON:
  87. #        print "Enciendo mi antorcha..."
  88.         EnciendeAntorcha(objright.Name)
  89.         if objrighttorch.Life>0.0:
  90.             Bladex.AddScheduledFunc(Bladex.GetTime()+objrighttorch.Life, ExtingueAntorcha, (objright.Name,))
  91.     else:
  92. #        print "Enciendo la antorcha de la pared..."
  93.         EnciendeAntorcha(torch.Name)
  94.         if torchobj.Life>0.0:
  95.             Bladex.AddScheduledFunc(Bladex.GetTime()+torchobj.Life, ExtingueAntorcha, (torch.Name,))
  96.  
  97.  
  98. def TorchUseFunc(torch_name, use_from):
  99.     global UseFunc
  100.     
  101.     torch=Bladex.GetEntity(torch_name)    
  102.     pj=Bladex.GetEntity("Player1")
  103.     objright=Bladex.GetEntity(pj.InvRight)
  104.     if objright and (torch.Kind in tipos_antorcha) and (objright.Kind in tipos_antorcha):
  105.         torchobj=torch.Data.torchobjdata
  106.         objrighttorch=objright.Data.torchobjdata
  107.         if (objrighttorch.LightStatus==OFF and torchobj.LightStatus==OFF) or (objrighttorch.LightStatus==ON and torchobj.LightStatus==ON):
  108. #            print "No puedo encender. Ambas antorchas estan encendidas o apagadas..."
  109.             return
  110.         if (torchobj.LiveStatus==DEAD) or (objrighttorch.LiveStatus==DEAD):
  111. #            print "Esta antorcha esta extinta..."
  112.             return
  113.         Actions.QuickTurnToFaceEntity("Player1", torch_name)
  114.         difalt=-(torch.Position[1]-(pj.Position[1]+pj.Dist2Floor))
  115.         chartype=Bladex.GetCharType(pj.CharType, pj.CharTypeExt)
  116.         if difalt<=chartype.MaxTake1:
  117.             pj.LaunchAnmType("fire_g")
  118.         elif difalt<=chartype.MaxTake2:
  119.             pj.LaunchAnmType("fire0")
  120.         elif difalt<=chartype.MaxTake3:
  121.             pj.LaunchAnmType("fire1")
  122.         elif difalt<=chartype.MaxTake4:
  123.             pj.LaunchAnmType("fire2")
  124.         elif difalt<=chartype.MaxTake5:
  125.             pj.LaunchAnmType("fire3")
  126.         else:
  127. #            print "Demasiado alta..."
  128.             return
  129.         if UseFunc:
  130.             UseFunc(torch.Name, objright.Name)
  131.         pj.AddAnmEventFunc("SetAlightEvent", EnciendeEstaAntorcha)
  132. #    else:
  133. #        print "No tengo antorcha..."
  134.  
  135.  
  136. def SetUsable(obj_name, light_int=3.0, fire_int=3.0, life=-1):
  137.     obj=Bladex.GetEntity(obj_name)
  138.     if obj.Kind not in tipos_antorcha:
  139. #        print "El objeto "+obj_name+" no es una antorcha o no esta definido como tal en tipos_antorcha"
  140.         return
  141.     torchobj=TorchObj()
  142.     torchobj.LightIntensity=light_int
  143.     torchobj.FireIntensity=fire_int
  144.     torchobj.Life=life
  145.     if AuxFuncs.GetSpot(obj).Intensity==0.0:
  146.         torchobj.LightStatus=OFF
  147.         if Reference.EntitiesObjectData.has_key(obj_name): del Reference.EntitiesObjectData[obj_name]
  148.     else:
  149.         torchobj.LightStatus=ON
  150.         Reference.EntitiesObjectData[obj_name]= Reference.DefaultObjectData["AntorchaFuego"]
  151.     if life==0:
  152.         torchobj.LiveStatus=DEAD
  153.     else:
  154.         torchobj.LiveStatus=ALIVE
  155.     InitDataField.Initialise(obj)
  156.     obj.Data.torchobjdata=torchobj
  157.     if obj.Kind!="Antorcha":    # This type is carryable
  158.         obj.UseFunc=TorchUseFunc
  159.  
  160.  
  161. UseFunc = None         # UseFunc(from,to)
  162.  
  163.  
  164. def SaveData(filename):
  165.   import cPickle
  166.   import GameStateAux
  167.  
  168.   funcfile=open(filename,"wt")
  169.   p=cPickle.Pickler(funcfile)
  170.   d=(GameStateAux.SaveFunctionAux(UseFunc),tipos_antorcha)
  171.  
  172.   p.dump(d)
  173.   funcfile.close()
  174.  
  175.  
  176. def LoadData(filename):
  177.   import cPickle
  178.   import GameStateAux
  179.  
  180.   funcfile=open(filename,"rt")
  181.   p=cPickle.Unpickler(funcfile)
  182.   d=p.load()
  183.   funcfile.close()
  184.   print d
  185.  
  186.   global UseFunc
  187.   global tipos_antorcha
  188.   
  189.   UseFunc=GameStateAux.LoadFunctionAux(d[0])
  190.   tipos_antorcha=d[1]
  191.  
  192.  
  193.  
  194. import GameState
  195. GameState.ModulesToBeSaved.append(__import__(__name__))
  196.